package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.fragment.AnswerMoreFragment;
import com.banshuibao.bsb_android.fragment.CoachMoreFragment;
import com.banshuibao.bsb_android.fragment.InterViewMoreFragment;
import com.banshuibao.bsb_android.fragment.LiveMoreFragment;
import com.banshuibao.bsb_android.fragment.TestMoreFragment;

public class MoreResultActivity extends BaseActivity {

    private String key, title, tag;
    private FragmentTransaction transaction;
    private FragmentManager manager;
    private Fragment answerFragment,liveFragment,coachFragment,testFragment,interFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more_result);
        key = getIntent().getStringExtra("key");
        title = getIntent().getStringExtra("title");
        tag = getIntent().getStringExtra("tag");
        manager = getSupportFragmentManager();
        getData();
    }


    public void getData() {
        transaction = manager.beginTransaction();
        switch (tag) {
            case "answer":
                setTitleText("专家答疑");
                if (answerFragment == null) {
                    answerFragment = new AnswerMoreFragment(key,title);
                    transaction.add(R.id.frameLayout, answerFragment, "answer");
                } else {
                    transaction.show(answerFragment);
                }
                break;
            case "live":
                setTitleText("财税课堂");
                if (liveFragment == null) {
                    liveFragment = new LiveMoreFragment(key,title);
                    transaction.add(R.id.frameLayout, liveFragment, "live");
                } else {
                    transaction.show(liveFragment);
                }
                break;
            case "coach":
                setTitleText("政策解读");
                if (coachFragment == null) {
                    coachFragment = new CoachMoreFragment(key,title);
                    transaction.add(R.id.frameLayout, coachFragment, "coach");
                } else {
                    transaction.show(coachFragment);
                }
                break;
            case "test":
                setTitleText("考前辅导");
                if (testFragment == null) {
                    testFragment = new TestMoreFragment(key,title);
                    transaction.add(R.id.frameLayout, testFragment, "test");
                } else {
                    transaction.show(testFragment);
                }
                break;
            case "inter":
                setTitleText("大咖访谈");
                if (interFragment == null) {
                    interFragment = new InterViewMoreFragment(key,title);
                    transaction.add(R.id.frameLayout, interFragment, "inter");
                } else {
                    transaction.show(interFragment);
                }
                break;
        }
        transaction.commit();
    }

}
